<template>
	<view class="box">
		<!-- 标签栏 -->
		<view class="tab">
			<u-tabs :list="list1" @click="click" lineColor="#109C7A" :current="active" :activeStyle="{
					color: '#333',
					fontSize: '32rpx',
					fontWeight: 'bold'
				}" :inactiveStyle="{
					color: '#999',
					fontSize: '32rpx',
				}"></u-tabs>
		</view>
		<!-- 空 -->
		<view class="none" v-if="!list.length">
			<view class="none-img f-w">
				<image src="https://jw.xzsw2021.com/static/big/icon_222@2x.png" mode=""></image>
			</view>
			<view class="f30 tr c666">暂时没有任何优惠券哦</view>
		</view>
		<!-- 列表 -->
		<view class="list" v-else>
			<template v-for="(item,index) of list">
				<!-- 满减/免运费券 -->
				<view class="card flex" v-if="item.type==1||item.type==3" :key="index">
					<view class="left">
						<view class="price">￥<text class="f40 bold">{{item.coupon_price}}</text></view>
						<view class="tj">满{{item.use_min_price}}可用</view>
					</view>
					<view class="right">
						<view class="one">{{item.title}}</view>
						<view class="two f24">{{item.create_time}}</view>
						<view class="three flex" @click="zhankai(index)">
							<view>
								<view class="desc" :class="!item.look?'hide-line':''" v-if="item.remarks">
									{{item.remarks}}
								</view>
							</view>
							<view class="icon" v-if="item.remarks.length>17">
								<image src="https://jw.xzsw2021.com/static/img/icon_62@2x.png" mode=""
									v-if="!item.look"></image>
								<image src="https://jw.xzsw2021.com/static/img/icon_63@2x.png" mode="" v-else></image>
							</view>
						</view>
						<!-- 立即领取 -->
						<view class="lingqu lingqu2" v-if="item.issue">
							已领取
						</view>
						<view class="lingqu lingqu2" @click="lingqu(item)" v-else>
							立即领取
						</view>
					</view>
				</view>
				<!-- 商品券样式 -->
				<view class="card" v-if="item.type==2" :key="index">
					<view class="right">
						<view class="one">{{item.title}}</view>
						<view class="two f24">{{item.create_time}}</view>
						<view class="three flex" @click="zhankai(index)">
							<view>
								<view class="desc" :class="!item.look?'hide-line':''" v-if="item.remarks">
									{{item.remarks}}
								</view>
							</view>
							<view class="icon" v-if="item.remarks.length>19">
								<image src="https://jw.xzsw2021.com/static/img/icon_62@2x.png" mode=""
									v-if="!item.look"></image>
								<image src="https://jw.xzsw2021.com/static/img/icon_63@2x.png" mode="" v-else></image>
							</view>
						</view>
						<!-- 立即领取 -->
						<view class="lingqu lingqu2" v-if="item.issue">
							已领取
						</view>
						<view class="lingqu lingqu2" @click="lingqu(item)" v-else>
							立即领取
						</view>
					</view>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	import {
		getCouponListApi,
		receiveCouponApi
	} from '@/api/coupon.js'

	import Cache from '@/util/cache.js'

	export default {
		data() {
			return {
				active: 0,
				list1: [{
						name: '全部',
						id: ''
					}, {
						name: '满减券',
						id: 3
					}, {
						name: '商品券',
						id: 1
					},
					{
						name: '免运费券',
						id: 2
					}
				], //标签
				list: [],
				search: {
					type: '',

				}
			}
		},
		created() {
			this.getList()
		},

		methods: {
			getList() {
				let market = JSON.parse(Cache.get('market'))
				getCouponListApi(market.id, this.search).then(res => {
					this.list = res.data
				}).catch(err => {
					console.log(err)
				})

			},
			//切换导航栏 
			click(item) {
				this.active = item.index
				this.list = []
				this.search.type = item.id
				this.getList()
			},
			// 展开
			zhankai(index) {
				this.list[index].look = !this.list[index].look;
			},
			//领取
			lingqu(item) {
				uni.showLoading({
					mask:true
				})
				receiveCouponApi(item).then(res => {
					uni.hideLoading()
					uni.showToast({
						title: res.message,
						icon: "none"
					})
					this.getList()
				}).catch(err => {

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		.tab {
			height: 96rpx;
			padding: 0 30rpx 0 0;
		}

		.none {
			.none-img {
				margin: 148rpx auto 80rpx;
				width: 376rpx;
				height: 329rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.list {
			min-height: calc(100vh - 96rpx);
			background-color: #F5F5F5;
			padding: 20rpx 30rpx;

			.card {
				position: relative;
				margin-bottom: 20rpx;
				width: 690rpx;
				// height: 186rpx;
				padding: 23rpx 28rpx 23rpx 0;
				background: #FFFFFF;
				border-radius: 10rpx;
				box-sizing: border-box;

				.left {
					flex-shrink: 0;
					width: 160rpx;
					height: 160rpx;
					border-right: 1rpx dashed #CCCCCC;
					text-align: center;
					color: #F83535;

					.price {
						margin-top: 28rpx;
					}

					.tj {
						margin-top: 6rpx;
						font-size: 24rpx;
						color: #666;
					}
				}

				.left2 {
					color: #D1D1D1;

					.tj {
						color: #D1D1D1;
					}
				}

				.right {
					position: relative;
					flex: 1;
					padding-right: 30rpx;
					margin-left: 30rpx;
					font-size: 28rpx;

					// background-color: pink;
					.two {
						margin: 28rpx 0;
						color: #666;
					}

					.three {
						color: #999;
						font-size: 24rpx;
						overflow: hidden;

						.desc {
							flex: 1;
							width: 420rpx;
						}

						.icon {
							flex-shrink: 0;
							margin-left: 20rpx;
							width: 26rpx;
							height: 14rpx;

							image {
								width: 100%;
								height: 100%;
							}
						}
					}

					.lingqu {
						position: absolute;
						right: 30rpx;
						top: 60rpx;
						width: 140rpx;
						height: 44rpx;
						line-height: 44rpx;
						text-align: center;
						background: #FFFFFF;
						border: 1rpx solid #F83535;
						border-radius: 22rpx;
						font-size: 26rpx;
						color: #F83535;
					}

					.lingqu2 {
						right: 0;
					}

					.get {
						border: 1rpx solid #ccc;
						color: #666;
					}
				}

				.right2 {
					color: #D1D1D1;

					.two,
					.three {
						color: #D1D1D1;
					}
				}
			}
		}
	}
</style>
